<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header(true)?>


    <?=$this->menu("user")?>


    <h1><?=$this->message("label.header", _User::BUNDLE)?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.header", _User::BUNDLE),
                "href"=>$this->path()."user/list"
            ),
            array(
                "name"=>($this->userForm->getUser()->getUserId() > 0 ?

                    $this->message("route.edit", _Core::BUNDLE) . " " .
                        "\"".$this->userForm->getUser()->getUserName()."\" " :

                    $this->message("route.new", _Core::BUNDLE) . " " .
                        strtolower($this->message("label.item", _User::BUNDLE)))
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _User::BUNDLE)?>


    <form id="<?=get_class($this->userForm)?>" action="user/save" method="post">

        <div>
            <input type="hidden"
                   name="user->userId"
                   value="<?=$this->userForm->getUser()->getUserId()?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.required", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("user->username")?>">
                <th><label for="username"><?=$this->message("prompt.username", _User::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="user->username"
                           id="username"
                           value="<?=$this->userForm->getUser()->getUserName()?>"
                           size="32"
                           type="text"
                           class="textInput" />
                           <p class="hint"><?=$this->message("note.username", _User::BUNDLE)?></p>
                </td>
            </tr>

            <? /* Passwords are required when editing new User. See below for optional passwords */ ?>
            <? if($this->userForm->getUser()->getUserId() <= 0): ?>

                <tr class="ctrl<?=$this->error("user->password")?>">
                    <th><label for="password"><?=$this->message("prompt.password", _User::BUNDLE)?></label></th>
                    <th class="required"><em>*</em></th>
                    <td>
                        <input name="user->password"
                               id="password"
                               value="<?=$this->userForm->getUser()->getPassword()?>"
                               size="32"
                               type="password"
                               class="textInput" />
                        <p class="hint"><?=$this->message("note.password", _User::BUNDLE)?></p>
                    </td>
                </tr>
                <tr class="ctrl<?=$this->error("password2")?>">
                    <th><label for="password2"><?=$this->message("prompt.password2", _User::BUNDLE)?></label></th>
                    <th class="required"><em>*</em></th>
                    <td>
                        <input name="password2"
                               id="password2"
                               value="<?=$this->userForm->getPassword2()?>"
                               size="32"
                               type="password"
                               class="textInput" />
                    </td>
                </tr>

            <? endif; ?>

            <tr class="ctrl<?=$this->error("roles")?>">
                <th><label for="roles"><?=$this->message("prompt.roles", _User::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <select name="roles[]" id="roles" multiple="multiple" size="5" class="textInput">
                        <? foreach($this->roles() as $role): ?>
                            <option
                                value="<?=$role->getRolename()?>"
                                <?=in_array($role->getRolename(), $this->userForm->getRoles()) ? " selected=\"selected\"" : ""?>>
                                <?=$role->getDescription()?>
                            </option>
                        <? endforeach; ?>
                    </select>
                    <p class="hint"><?=$this->message("note.multiple", _Core::BUNDLE, null, null, false)?></p>
                </td>
            </tr>

            </table>

        </fieldset>

        <? /* Passwords are optional when editing existing User */ ?>
        <? if($this->userForm->getUser()->getUserId() > 0): ?>

            <fieldset>

                <legend><?=$this->message("label.optional", _Core::BUNDLE)?></legend>

                <table cellspacing="0" cellpadding="0" class="form">
                <tr class="ctrl<?=$this->error("user->password")?>">
                    <th><label for="password"><?=$this->message("prompt.password", _User::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <input name="user->password"
                               id="password"
                               value="<?=$this->userForm->getUser()->getPassword()?>"
                               size="32"
                               type="password"
                               class="textInput" />
                        <p class="hint"><?=$this->message("note.password", _User::BUNDLE)?></p>
                    </td>
                </tr>
                <tr class="ctrl<?=$this->error("password2")?>">
                    <th><label for="password2"><?=$this->message("prompt.password2", _User::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <input name="password2"
                               id="password2"
                               value="<?=$this->userForm->getPassword2()?>"
                               size="32"
                               type="password"
                               class="textInput" />
                    </td>
                </tr>
                </table>

            </fieldset>

        <? endif; ?>

        <div class="buttons">

            <input type="button"
                   onclick="to('user/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer("users")?>